import {Component, Input, OnInit} from '@angular/core';
import {Observable} from "rxjs";
import {Student} from "../student";
import {StudentService} from "../student.service";

@Component({
  selector: 'app-student-datagrid',
  templateUrl: './student-datagrid.component.html',
  styleUrls: ['./student-datagrid.component.css']
})
export class StudentDatagridComponent implements OnInit {
  pageNum:number=1;
  pages:number;
  @Input()pageSize:number=3;
  students:Student[];
  constructor(private studentSerive:StudentService) { }

  ngOnInit() {
    this.getData()
  }
  up(){
    if(this.pageNum>1)
      this.pageNum--;
    this.getData();
  }
  down(){
    if(this.pageNum<this.pages)
      this.pageNum++;
    this.getData();
  }
  change(){
    this.pageNum=1;
    this.getData()
  }
  /*分页功能*/
  getData(){
    this.studentSerive.list(this.pageNum,this.pageSize).subscribe(pageInfo=>{
      this.pages = Math.ceil(pageInfo.total / this.pageSize)
      this.students = pageInfo.rows
    })
  }
}
